//
//  merchantListCell.m
//  cityStar
//
//  Created by joyban on 14-12-24.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "merchantListCell.h"
#import "UIImageView+WebCache.h"

@implementation merchantListCell

+(CGFloat)heightOfTableCell
{
    return 105;
}

-(void)setDataWithModeli:(supplierlibsModel *)model
{
    self.Placelabel.text = [NSString stringWithFormat:@"%@",model.title];
    [self.heardimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.icszx.com/image/c/id/%@/w/105/h/87/m/0",[NSString stringWithFormat:@"%@",model.image]]] placeholderImage:[UIImage imageNamed:@"商户列表_img"]];
    self.heardimage.contentMode =  UIViewContentModeCenter;
    self.titleTable.text = [NSString stringWithFormat:@"%@",model.name];
//    if ([NSString stringWithFormat:@"%@",model.mobile].length > 6) {
        self.telLabel.text = [NSString stringWithFormat:@"%@",model.mobile];
//    }else{
//        self.telLabel.text = [NSString stringWithFormat:@"%@",merchant.service_mobile];
//    }
    
    NSArray *discountArr = [[NSString stringWithFormat:@"%@",model.discount] componentsSeparatedByString:@","];
    NSArray *buttonArray = [[NSArray alloc]initWithObjects:self.btn1,self.btn2,self.btn3,self.btn4,self.btn5,nil];
    NSMutableArray *btnArray = [[NSMutableArray alloc]init];
    if (discountArr > 0) {
        [discountArr enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
            UIButton *senderbtn = buttonArray[idx];
            switch ([obj integerValue]) {
                case 1:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"cheng"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];
                }
                    break;
                case 2:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"re"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];
                    
                }
                    break;
                case 3:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"tuan"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];
                    
                }
                    break;
                case 4:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];
                    
                }
                    break;
                case 5:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"quan"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];
                    
                }
                    break;
                default:
                    break;
            }
        }];
    }
    [buttonArray enumerateObjectsUsingBlock:^(UIButton *obj, NSUInteger idx, BOOL *stop) {
        if (idx < btnArray.count) {
            obj.hidden = NO;
        }else{
            obj.hidden = YES;
        }
    }];
}

-(void)configWithMerchant:(GetSupplierQuery *)merchant
{
    self.Placelabel.text = [NSString stringWithFormat:@"%@",merchant.address];
    [self.heardimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://api.icszx.com/image/c/id/%@/w/105/h/87/m/0",[NSString stringWithFormat:@"%@",merchant.cover]]] placeholderImage:[UIImage imageNamed:@"商户列表_img"]];
    self.heardimage.contentMode =  UIViewContentModeCenter;
    self.titleTable.text = [NSString stringWithFormat:@"%@",merchant.name];
    if ([NSString stringWithFormat:@"%@",merchant.telphone].length > 6) {
        self.telLabel.text = [NSString stringWithFormat:@"%@",merchant.telphone];
    }else{
        self.telLabel.text = [NSString stringWithFormat:@"%@",merchant.service_mobile];
    }
    
    NSArray *discountArr = [[NSString stringWithFormat:@"%@",merchant.discount] componentsSeparatedByString:@","];
    NSArray *buttonArray = [[NSArray alloc]initWithObjects:self.btn1,self.btn2,self.btn3,self.btn4,self.btn5,nil];
    NSMutableArray *btnArray = [[NSMutableArray alloc]init];
    if (discountArr > 0) {
        [discountArr enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
            UIButton *senderbtn = buttonArray[idx];
            switch ([obj integerValue]) {
                case 1:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"cheng"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];
                }
                    break;
                case 2:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"re"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];

                }
                    break;
                case 3:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"tuan"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];

                }
                    break;
                case 4:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];

                }
                    break;
                case 5:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"quan"] forState:UIControlStateNormal];
                    [btnArray addObject:senderbtn];

                }
                    break;
                default:
                    break;
            }
        }];
    }
    [buttonArray enumerateObjectsUsingBlock:^(UIButton *obj, NSUInteger idx, BOOL *stop) {
        if (idx < btnArray.count) {
            obj.hidden = NO;
        }else{
            obj.hidden = YES;
        }
    }];
    
}

- (void)awakeFromNib {
//    [self removeFromSuperview];
//    self.btn1.layer.cornerRadius = 4.0;
//    self.btn2.layer.cornerRadius = 4.0;
//    self.btn3.layer.cornerRadius = 4.0;
//    self.btn4.layer.cornerRadius = 4.0;
//    self.btn5.layer.cornerRadius = 4.0;
//    self.btn1.hidden = YES;
//    self.btn2.hidden = YES;
//    self.btn3.hidden = YES;
//    self.btn4.hidden = YES;
//    self.btn5.hidden = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
